package com.zillion.health.service.impl;

import com.zillion.common.core.domain.entity.SysUser;
import com.zillion.common.core.domain.model.LoginUser;
import com.zillion.common.utils.SecurityUtils;
import com.zillion.health.domain.HealthPersonInfo;
import com.zillion.health.mapper.HealthPersonInfoMapper;
import com.zillion.health.service.IHealthPersonInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 人员信息Service业务层处理
 *
 * @author zillion
 * @date 2025-06-01
 */
@Service
public class HealthPersonInfoServiceImpl implements IHealthPersonInfoService {
    @Autowired
    private HealthPersonInfoMapper healthPersonInfoMapper;

    /**
     * 查询人员信息
     *
     * @param id 人员信息主键
     * @return 人员信息
     */
    @Override
    public HealthPersonInfo selectHealthPersonInfoById(Long id) {
        return healthPersonInfoMapper.selectHealthPersonInfoById(id);
    }

    /**
     * 查询人员信息列表
     *
     * @param healthPersonInfo 人员信息
     * @return 人员信息
     */
    @Override
    public List<HealthPersonInfo> selectHealthPersonInfoList(HealthPersonInfo healthPersonInfo) {
        // 获取当前登录用户信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        // 获取当前登录用户的部门ID
        Long deptId = user.getDeptId();
        healthPersonInfo.setDeptId(deptId);
        if  (user.isAdmin()) {
            healthPersonInfo.setDeptId(null);
        }
        return healthPersonInfoMapper.selectHealthPersonInfoList(healthPersonInfo);
    }

    /**
     * 新增人员信息
     *
     * @param healthPersonInfo 人员信息
     * @return 结果
     */
    @Override
    public int insertHealthPersonInfo(HealthPersonInfo healthPersonInfo) {
        return healthPersonInfoMapper.insertHealthPersonInfo(healthPersonInfo);
    }

    /**
     * 修改人员信息
     *
     * @param healthPersonInfo 人员信息
     * @return 结果
     */
    @Override
    public int updateHealthPersonInfo(HealthPersonInfo healthPersonInfo) {
        return healthPersonInfoMapper.updateHealthPersonInfo(healthPersonInfo);
    }

    /**
     * 批量删除人员信息
     *
     * @param ids 需要删除的人员信息主键
     * @return 结果
     */
    @Override
    public int deleteHealthPersonInfoByIds(Long[] ids) {
        return healthPersonInfoMapper.deleteHealthPersonInfoByIds(ids);
    }

    /**
     * 删除人员信息信息
     *
     * @param id 人员信息主键
     * @return 结果
     */
    @Override
    public int deleteHealthPersonInfoById(Long id) {
        return healthPersonInfoMapper.deleteHealthPersonInfoById(id);
    }
}
